package com.ruoyi.project.system.userCoachBind.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.userCoachBind.domain.UserCoachBind;
import com.ruoyi.project.system.userCoachBind.service.IUserCoachBindService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 学员教练绑定信息操作处理
 * 
 * @author zhangshilin
 * @date 2019-07-26
 */
@Controller
@RequestMapping("/system/userCoachBind")
public class UserCoachBindController extends BaseController
{
    private String prefix = "system/userCoachBind";
	
	@Autowired
	private IUserCoachBindService userCoachBindService;
	
	@RequiresPermissions("system:userCoachBind:view")
	@GetMapping()
	public String userCoachBind()
	{
	    return prefix + "/userCoachBind";
	}
	
	/**
	 * 查询学员教练绑定列表
	 */
	@RequiresPermissions("system:userCoachBind:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(UserCoachBind userCoachBind)
	{
		startPage();
        List<UserCoachBind> list = userCoachBindService.selectUserCoachBindList(userCoachBind);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出学员教练绑定列表
	 */
	@RequiresPermissions("system:userCoachBind:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(UserCoachBind userCoachBind)
    {
    	List<UserCoachBind> list = userCoachBindService.selectUserCoachBindList(userCoachBind);
        ExcelUtil<UserCoachBind> util = new ExcelUtil<UserCoachBind>(UserCoachBind.class);
        return util.exportExcel(list, "userCoachBind");
    }
	
	/**
	 * 新增学员教练绑定
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存学员教练绑定
	 */
	@RequiresPermissions("system:userCoachBind:add")
	@Log(title = "学员教练绑定", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(UserCoachBind userCoachBind)
	{		
		return toAjax(userCoachBindService.insertUserCoachBind(userCoachBind));
	}

	/**
	 * 修改学员教练绑定
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		UserCoachBind userCoachBind = userCoachBindService.selectUserCoachBindById(id);
		mmap.put("userCoachBind", userCoachBind);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存学员教练绑定
	 */
	@RequiresPermissions("system:userCoachBind:edit")
	@Log(title = "学员教练绑定", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(UserCoachBind userCoachBind)
	{		
		return toAjax(userCoachBindService.updateUserCoachBind(userCoachBind));
	}
	
	/**
	 * 删除学员教练绑定
	 */
	@RequiresPermissions("system:userCoachBind:remove")
	@Log(title = "学员教练绑定", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(userCoachBindService.deleteUserCoachBindByIds(ids));
	}
	
}
